package com.sxz.sbs.module.amortize.adapter;

import android.support.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sxz.sbs.R;
import com.sxz.sbs.module.amortize.AmortizeBankBean;

import java.util.List;

/**
 * @author : tian
 * time   : 2018/03/21
 * desc   :
 */

public class AmortizeAdapter extends BaseQuickAdapter<AmortizeBankBean.DataListBean,BaseViewHolder>{
    private int defaultSelection = -1;
    private boolean isFirst = true;
    public AmortizeAdapter(@Nullable List<AmortizeBankBean.DataListBean> data) {
        super(R.layout.item_amortize_bank_layout,data);
    }

    @Override
    protected void convert(BaseViewHolder helper, AmortizeBankBean.DataListBean item) {
        helper.setText(R.id.tv_item_amortize_number,"分"+item.getNumBers()+"期");
        if (item.getIsDefault() == 1) {
            helper.setVisible(R.id.iv_amortize_recommend,true);
        } else {
            helper.setVisible(R.id.iv_amortize_recommend,false);
        }
        if (defaultSelection == helper.getAdapterPosition()) {
            helper.setBackgroundRes(R.id.rl_amortize_bank,R.drawable.amortize_number_shape_y);
            helper.setTextColor(R.id.tv_item_amortize_number,mContext.getResources().getColor(R.color.color_white));
        } else {
            helper.setBackgroundRes(R.id.rl_amortize_bank,R.drawable.amortize_number_shape_n);
            helper.setTextColor(R.id.tv_item_amortize_number,mContext.getResources().getColor(R.color.color_text_3));
        }
        if (helper.getAdapterPosition() == 0 && isFirst) {
            isFirst = false;
            helper.setBackgroundRes(R.id.rl_amortize_bank,R.drawable.amortize_number_shape_y);
            helper.setTextColor(R.id.tv_item_amortize_number,mContext.getResources().getColor(R.color.color_white));
        }
    }
    public void setSelectPosition(int i) {
        this.defaultSelection = i;
        notifyDataSetChanged();
    }
    public void selectPosition(int i) {
        this.defaultSelection = i;
    }
    public void setFirst(boolean isFirst) {
        this.isFirst = isFirst;
    }
}
